#include "crc.h"
#include "Global.h"
#include "my_common.h"

// CRC-16-CCITT X16+X12+X5+1
unsigned long crc16(unsigned long seed, unsigned char *buffer, unsigned long length)
{
	unsigned long crc_result=0;//,i=0;

	CRC->CRCD = 0;
	#if 0
	for(i = 0;i < length;i++)
	{
		uint8_t t = buffer[i]; 
		CRC->CRCIN = t;
	}
	#endif
	while (length--)
	{
		wb(&CRC->CRCIN, *buffer++); // byte write
	}

	
	crc_result = CRC->CRCD;
	return crc_result;
}

